// 引入一级路由组件
// import Home from "@/pages/Home";
// import Search from "@/pages/Search";
// import Login from "@/pages/Login";
// import Register from "@/pages/Register";
// import Detail from "@/pages/Detail";
// import AddCartSuccess from "@/pages/AddCartSuccess";
// import ShopCart from "@/pages/ShopCart";
// import Trade from "@/pages/Trade";
// import Pay from "@/pages/Pay";
// import PaySuccess from "@/pages/PaySuccess";
// import Center from "@/pages/Center";

// 引入二级路由组件
// import MyOrder from "@/pages/Center/myOrder";
// import GroupOrder from "@/pages/Center/groupOrder";

/* 
component: () => import('@/pages/Search')
1. import(modulePath): 动态import引入模块, 被引入的模块会被单独打包
2. 组件配置的是一个函数, 函数中通过import动态加载模块并返回, 
    初始时函数不会执行, 第一次访问对应的路由才会执行, 也就是说只有一次请求对应的路由路径才会请求加载单独打包的js
作用: 用于提高首屏的加载速度
*/

// 路由的配置信息
export default [
  {
    path: "/center",
    redirect: "/center/myorder", // 重定向到myorder
    component: ()=>import('@/pages/Center'),
    // 二级路由组件
    children: [
      {
        path: "myorder",
        component: ()=>import('@/pages/Center/myOrder'),
      },
      {
        path: "grouporder",
        component:()=>import('@/pages/Center/groupOrder'),
      },
    ],
    meta: { show: true }, // 路由元信息（是否展示）
  },
  {
    path: "/paysuccess",
    component: ()=>import('@/pages/PaySuccess'),
    meta: { show: true }, 
  },
  {
    path: "/pay",
    component:()=>import('@/pages/Pay'),
    meta: { show: true }, 
    beforeRouteEnter (to, from, next) {
      // 去支付面，必须是从交易面而来
      if (from.path == '/trade') {
        next();
      }else {
        next();
      }
    }
  },
  {
    path: "/trade",
    component:()=>import('@/pages/Trade'),
    meta: { show: true }, 
    // 路由独享守卫
    beforeEnter: (to, from, next) => {
      // 去交易面，必须是从购物车而来
      if (from.path == "/shopcart") {
        next();
      } else {
        // 其他路由组件 停留在当前
        next(false);
      }
    }
  },
  {
    path: "/shopcart",
    component: ()=>import('@/pages/ShopCart'),
    meta: { show: true }, 
  },
  {
    path: "/addcartsuccess",
    name: "addcartsuccess",
    component: ()=>import('@/pages/AddCartSuccess'),
    meta: { show: true }, 
  },
  {
    path: "/detail/:skuid",
    component: ()=>import('@/pages/Detail'),
    meta: { show: true }, 
  },
  {
    path: "/home",
    component: ()=>import('@/pages/Home'),   // 路由懒加载
    meta: { show: true }, 
  },
  {
    name: "search",
    path: "/search/:keyword?", // 使用占位符声明接收params参数 加个问号表示可传参或不传参
    component: ()=>import('@/pages/Search'),
    meta: { show: true },
  },
  {
    path: "/login",
    component: ()=>import('@/pages/Login'),
    meta: { show: false },
  },
  {
    path: "/register",
    component: ()=>import('@/pages/Register'),
    meta: { show: false },
  },
  // 重定向 在项目跑起来的时候 访问 / 立马让它定向到首页
  {
    path: "*",
    redirect: "/home",
  },
];
